/*
* @Author: zhanghang
* @Date:   2018-05-20 14:53:33
* @Last Modified by:   zhanghang
* @Last Modified time: 2018-05-20 15:44:26
*/
import React from 'react'
import {Link,Route,Redirect} from 'react-router-dom'
import {connect }from 'react-redux'
import  App from './app.js'
import {logout} from './Auth.redux.js'
function Erying() {
    return <h2>2营</h2>
}
function Qibinglian() {
    return <h2>骑兵连</h2>
}

class Test extends React.Component {
    constructor(props){
        super(props)
    }
    render(){
        return <h2>测试组件{this.props.match.params.location}</h2>
    }
}

@connect(
    state=>state.auth,{
        logout
    }
    )
class Dashborad extends React.Component {
    constructor(props){
        super(props)
    }

    render(){
        const match = this.props.match
        const redirectToLogin = <Redirect to="/login"></Redirect>
        const app = (
        <div>
            <h1>独立团</h1>
            {this.props.isAuth?<button onClick={this.props.logout}>注销</button>: null}
        <ul>
                <li>
                 <Link exact to={`${match.url}/`}>一营</Link>
                </li>
                <li>
                 <Link to={`${match.url}/erying`}>二营</Link>
                </li>
                <li>
                 <Link to={`${match.url}/qibinglian`}>骑兵连</Link>
                </li>

            </ul>
            <Route path={`${match.url}/`} component={App}></Route>
            <Route path={`${match.url}/erying`} component={Erying}></Route>
            <Route path={`${match.url}/qibinglian`}component={Qibinglian}></Route>
            </div>
            )
        return this.props.isAuth?app: redirectToLogin
    }
}

export default Dashborad